package com.whz.governance.http.ribbon.context;

import lombok.experimental.UtilityClass;

/**
 * @author whz
 */
@UtilityClass
public class RibbonFilterContextHolder {

  private static final ThreadLocal<RibbonFilterContext> CONTEXT_THREAD_LOCAL_HOLDER = new InheritableThreadLocal<RibbonFilterContext>() {
    @Override
    protected RibbonFilterContext initialValue() {
      return new DefaultRibbonFilterContext();
    }
  };

  /**
   * Retrieves the current thread bound instance of {@link RibbonFilterContext}.
   *
   * @return the current context
   */
  public static RibbonFilterContext getCurrentContext() {
    return CONTEXT_THREAD_LOCAL_HOLDER.get();
  }

  /**
   * Clears the current context.
   */
  public static void clearCurrentContext() {
    CONTEXT_THREAD_LOCAL_HOLDER.remove();
  }
}